package likou;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/06/19 09:27
 */
public class _525 {
    public static void main(String[] args) {
        System.out.println(findMaxLength(new int[]{1,0}));
    }
    public static int findMaxLength(int[] nums) {
        int n = nums.length;
        int[] weizhi = new int[n];
        int sum = 0;
        int res = 0;
        for(int i=0;i<n;i++){
            sum+=nums[i];
            weizhi[i] = sum;
            if(i%2==1&&(i+1)/2==sum){
                res = i+1;
            }
            for(int j=(i)%2;j<i;j+=2){
                if(res>i-j){
                    break;
                }
                if(sum - weizhi[j]==(i-j)/2){
                    res = Math.max(i-j,res);
                }
            }
        }
        return res;
    }
}
